package bigdata.backend.mata.test;

import bigdata.backend.meta.entity.DorisColumnMeta;
import bigdata.backend.meta.entity.DorisTableMeta;
import bigdata.backend.meta.service.*;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
public class TestDorisDdlGenerator {
    @Autowired
    private DorisDdlGenerator dorisDdlGenerator;

    @Autowired
    private DorisTableMetaService dorisTableMetaService;

    @Autowired
    private DorisColumnMetaService dorisColumnMetaService;

    @Test
    public void test01() {
        Long tableId = 1986729767194632194L;
        DorisTableMeta table = dorisTableMetaService.getById(tableId);
        List<DorisColumnMeta> columns = dorisColumnMetaService.lambdaQuery()
                .eq(DorisColumnMeta::getTableId, tableId)
                .orderByAsc(DorisColumnMeta::getOrdinalPosition)
                .list();
        String sql = dorisDdlGenerator.generateDdl(table, columns);
        System.out.println(sql);
    }

    @Test
    public void test02() {
        DorisColumnMeta columnMeta = dorisColumnMetaService.getById("1987103616900771843");
        String res = dorisDdlGenerator.buildColumnDefinition(columnMeta);
        System.out.println(res);
    }
}
